from ..extensions import db

class QhBetting(db.Model):
    __bind_key__ = 'qhjy'
    __tablename__='qh_betting'
    # __table_args__ = {"useexisting": True}
    id=db.Column(db.Integer,primary_key=True,autoincrement=True)
    user_id = db.Column(db.Integer, db.ForeignKey('jys.bf_user.id'),nullable=False)
    tw_qh_coin = db.Column(db.Integer,nullable=False)
    nper_id = db.Column(db.Integer,db.ForeignKey('qh_nper.id'),nullable=False)
    type=db.Column(db.SmallInteger,nullable=False)
    price= db.Column(db.Numeric(15, 6), default=0,nullable=False)
    add_time = db.Column(db.Integer,nullable=False)
    is_true=db.Column(db.SmallInteger,index=True,nullable=False)
    poundage= db.Column(db.Numeric(18, 10), default=0,nullable=False)
    rate = db.Column(db.Numeric(7, 4), default=0,nullable=False)
class QhBettingFase(db.Model):
    __bind_key__ = 'qhjy'
    __tablename__='qh_betting_false'
    id=db.Column(db.Integer,primary_key=True,autoincrement=True,onupdate=0)
    username=db.Column(db.String(200), nullable=False, comment="用户名",default='')
    price = db.Column(db.Numeric(18,8), default=0)
    type = db.Column(db.Integer)
    coin_id=db.Column(db.Integer)
    nper_id= db.Column(db.Integer,db.ForeignKey('qh_nper.id'))
    rate = db.Column(db.Numeric(18,8), default=0)
    add_time=db.Column(db.Integer)

class QhConfig(db.Model):
    __bind_key__ = 'qhjy'
    __tablename__='qh_config'
    id=db.Column(db.Integer,primary_key=True,autoincrement=True,onupdate=0)
    is_open=db.Column(db.Integer)
    next_open_time=db.Column(db.String(20), nullable=False, comment="",default='')
    rate = db.Column(db.Numeric(8,5), default=0)
    max_betting_price = db.Column(db.Numeric(15,7), default=0)
    min_betting_price=db.Column(db.Numeric(15,7), default=0)
    max_flat_deviation = db.Column(db.Numeric(18, 8), default=0)
    min_flat_deviation = db.Column(db.Numeric(18, 8), default=0)
    btc_error= db.Column(db.Numeric(18,8), default=0)
    eth_error = db.Column(db.Numeric(18,8), default=0)
    open_success=db.Column(db.Integer)

class QhNper(db.Model):
    __bind_key__ = 'qhjy'
    __tablename__='qh_nper'
    id=db.Column(db.Integer,primary_key=True,autoincrement=True,onupdate=0)
    nper=db.Column(db.Integer)
    open_time = db.Column(db.Integer)
    add_time=db.Column(db.Integer)
    coin_id = db.Column(db.Integer)
    result= db.Column(db.Integer)
    is_current = db.Column(db.Integer)
    up_rate=db.Column(db.Numeric(28,18), default=0)
    down_rate=db.Column(db.Numeric(28,18), default=0)
    flat_rate=db.Column(db.Numeric(28,18), default=0)
    result_rate=db.Column(db.Numeric(28,18), default=0)
    stop_time=db.Column(db.Integer)
    end_time = db.Column(db.Integer)
    betting = db.relationship('QhBetting', backref='betting_user', lazy='dynamic')
    betting_false = db.relationship('QhBettingFalse', backref='betting_false_user', lazy='dynamic')
    result = db.relationship('QhBettingFalse', backref='result_user', lazy='dynamic')

class QhResult(db.Model):
    __bind_key__ = 'qhjy'
    __tablename__='qh_result'
    id=db.Column(db.Integer,primary_key=True,autoincrement=True,onupdate=0)
    nper_id=db.Column(db.Integer,db.ForeignKey('qh-nper.id'))
    coin_id = db.Column(db.Integer)
    exchange_name=db.Column(db.String(255), nullable=False, comment="",default='')
    open_time_price=db.Column(db.Numeric(15, 8), default=0)
    end_time_price= db.Column(db.Numeric(15, 8), default=0)